﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace _3D
{
    abstract class GameObject3D
    {
        public BoundingBox bBox;
        public GameObject3D() { }
        public Model modelo;
        protected Matrix world;
        Matrix view;
        public Vector3 position;

        public GameObject3D(Model modelo)
        {
            this.modelo = modelo;
        }
        public virtual void Update(Camera camera)
        {}
        public virtual void Draw(GraphicsDevice graphics)
        {}
        public virtual void Draw3D(GraphicsDevice graphics, Camera camera)
        {
            Matrix[] transforms = new Matrix[this.modelo.Bones.Count];
            this.modelo.CopyAbsoluteBoneTransformsTo(transforms);
            foreach (ModelMesh mesh in modelo.Meshes)
            {
                foreach (BasicEffect e in mesh.Effects)
                {
                    e.View = camera.view;
                    //e.View *= Matrix.CreateTranslation(camera.position);
                    e.EnableDefaultLighting();
                    e.Projection = camera.projection;
                    //e.View = camera.view;
                    e.World = world * mesh.ParentBone.Transform;
                }
                mesh.Draw();
            }
        }
    }
}
